package com.example.project.controller.merchant;

import com.example.project.common.Result;
import com.example.project.dto.request.ProductRequest;
import com.example.project.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/merchant/products")
@RequiredArgsConstructor
public class MerchantProductController {

    private final ProductService productService;

    @PostMapping
    public Result<?> createProduct(@RequestBody @Valid ProductRequest request, 
                                 @RequestAttribute Long userId) {
        return productService.createProduct(request, userId);
    }

    @PutMapping("/{id}")
    public Result<?> updateProduct(@PathVariable Long id,
                                 @RequestBody @Valid ProductRequest request, 
                                 @RequestAttribute Long userId) {
        return productService.updateProduct(id, request, userId);
    }

    @DeleteMapping("/{id}")
    public Result<?> deleteProduct(@PathVariable Long id, 
                                 @RequestAttribute Long userId) {
        return productService.deleteProduct(id, userId);
    }

    @GetMapping
    public Result<?> getProductList(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  @RequestAttribute Long userId) {
        return productService.getProductList(pageNum, pageSize, userId);
    }

    @PutMapping("/{id}/status")
    public Result<?> updateProductStatus(@PathVariable Long id,
                                       @RequestParam Integer status,
                                       @RequestAttribute Long userId) {
        return productService.updateProductStatus(id, status, userId);
    }
} 